package com.xbs.controller.user;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xbs.controller.base.BaseServlet;
import com.xbs.entity.UserEntity;
import com.xbs.service.user.MessageService;
@WebServlet("/userview/myCenter/loginpwd")
public class MyCenter_loginpwd extends BaseServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		forward("/userview/myCenter/myCenter_loginpwd");
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String uname = (String) req.getSession().getAttribute("uname");
		String oldps = req.getParameter("oldps");
		String newps = req.getParameter("newps");
		String pwda = req.getParameter("pwda");
		MessageService messageservice = new MessageService();
		UserEntity str1 = messageservice.selAll(uname);
		if(oldps == null || oldps.equals("")){
			String str7 = "请输入原始密码！";
			req.setAttribute("password5", str7);
		}else if(str1.getUser_password().equals(oldps)){
			if(newps == null || newps.equals("")){
				String str2 = "请输入新密码！";
				req.setAttribute("password1", str2);
			}else if(pwda == null || pwda.equals("")){
				String str3 = "请确认密码！";
				req.setAttribute("password2", str3);
			}else if(newps.equals(pwda)){
				messageservice.updatePwd(pwda, oldps);
				String str6 = "修改成功！";
				req.setAttribute("password4", str6);
			}else{
				String str4 = "两次输入的密码不一样！";
				req.setAttribute("password3", str4);
			}
		}else{
			String str5 = "原始密码错误！";
			req.setAttribute("password", str5);
		}
		
		forward("/userview/myCenter/myCenter_loginpwd");
	}
}
